**********************************************************************************************************
** Tinkering with Executive Term Limits: Partisan Imbalance and Institutional Weakness in Latin America  *
** Author: Gabriel Negretto                                                                              *
** Date: August 2021                                                                                       * **********************************************************************************************************   



****************************************************************************************************************************************************************************
** Analysis 1: Survival model
** Dependent variable: time to reform a restrictive presidential reelection regime that probihits consecutive presidential reelection or allows it for only one term (one-term extension reform as failtype=1 and unlimited reelection reform as failtype==2)
****************************************************************************************************************************************************************************


*preparing data for survival analysis 

stset   t_end, id (restreelecreg_id) failure (failtype)   


*Cox models 

*Models 1 and 2 (All reforms relaxing restrictive term limits) 


stcox   partisan_imbalance constraints_legacy, cluster (country_code) efron  
 

stcox   partisan_imbalance constraints_legacy  jud_attack exec_approval  prespart_age  prespart_policy  v2x_execorr  gdppcgr_mad_lag, cluster (country_code) efron  
 

 
*Proportional hazards assumption test
 
stcox   partisan_imbalance  constraints_legacy jud_attack exec_approval  prespart_age  prespart_policy  v2x_execorr  gdppcgr_mad_lag, cluster (country_code) efron    scaledsch(sca*) schoenfeld(sch*)

stphtest, rank detail



*Models 3 and 4 (One-term extensions)

streset, failure (failtype == 1)

stcox   partisan_imbalance constraints_legacy, cluster (country_code) efron   
 
 
stcox   partisan_imbalance constraints_legacy  jud_attack exec_approval  prespart_age  prespart_policy  v2x_execorr  gdppcgr_mad_lag, cluster (country_code) efron
 



*Models 5 and 6 (Multiple reelections)

streset, failure (failtype == 2)

stcox   partisan_imbalance constraints_legacy, cluster (country_code) efron   
 
 
stcox   partisan_imbalance constraints_legacy   jud_attack exec_approval  prespart_age  prespart_policy  v2x_execorr  gdppcgr_mad_lag, cluster (country_code) efron
 




**Graph survival*

stset   t_end, id (restreelecreg_id) failure (failtype) 

stcox   partisan_imbalance constraints_legacy, cluster (country_code) efron  

stcurve, surv at1(partisan_imbalance= 0) at2(partisan_imbalance= 30)  at3(partisan_imbalance= 60) range(1 30)

stcurve, surv at1(constraints_legacy= 1) at2(constraints_legacy= 2.5) at3(constraints_legacy= 5) range(1 30)


**Graph hazard*

stset   t_end, id (restreelecreg_id) failure (failtype) 

stcox   partisan_imbalance constraints_legacy, cluster (country_code) efron  

stcurve, hazard at1 (partisan_imbalance= 0) at2(partisan_imbalance= 30) at3(partisan_imbalance= 60)    

stcurve, hazard at1(constraints_legacy= 1) at2(constraints_legacy= 2.5) at3(constraints_legacy= 5)
 

***************************************************************************************************************************************************************************** 
** Analysis 2: Ordered Logistic Regression
** Dependent variable: Degree of departure from a ban on consecutive reelection: no reform (0), one-term extension (1), multiple reelections (2) 
******************************************************************************************************************************************************************************



*preparing data for ordered logit analysis 

xtset country_code  year
 



*Models
 

xtologit  faildegree partisan_imbalance constraints_legacy t t2 t3, vce (cluster country_code) or
 

xtologit  faildegree partisan_imbalance constraints_legacy  jud_attack exec_approval prespart_age prespart_policy  v2x_execorr gdppcgr_mad_lag t t2 t3, vce (cluster country_code) or 
 

xtologit  faildegree c.partisan_imbalance##c.constraints_legacy jud_attack exec_approval prespart_age prespart_policy v2x_execorr gdppcgr_mad_lag t t2 t3, vce (cluster country_code) or
  
  


*Figures with predicted probabilities of outcome 1 (one-term extension) and outcome 2 (multiple reelections) based on the interactive model  



margins, at(constraints_legacy=1  partisan_imbalance=(0(10)90) (mean) _all) pr(out(1)) pr(out(2)) 

marginsplot



margins, at(constraints_legacy=5  partisan_imbalance=(0(10)90) (mean) _all) pr(out(1)) pr(out(2)) 

marginsplot 



*Graph Effect of time on each outcome

xtologit  faildegree partisan_imbalance constraints_legacy t t2 t3, vce (cluster country_code) or


margins, at( t=(1(1)38) (median) _all) pr(out(0)) nose
marginsplot, recast(line)


margins, at( t=(1(1)38) (median) _all)  pr(out(1))  nose
marginsplot, recast(line)

margins, at( t=(1(1)38) (median) _all) pr(out(2)) nose
marginsplot, recast(line)


*parallel regression assumption test

gen interact= partisan_imbalance*constraints_legacy


ologit  faildegree partisan_imbalance constraints_legacy interact  jud_attack exec_approval prespart_age prespart_policy v2x_execorr t t2 t3, vce (cluster country_code) or

brant, detail

